package com.briup.mt.service.impl;

import com.briup.mt.bean.Article;
import com.briup.mt.bean.ArticleExample;


import com.briup.mt.bean.BaseUserRole;
import com.briup.mt.dao.ArticleMapper;
import com.briup.mt.service.ICmsArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;
import java.util.List;

/**
 * @author 武文科
 * @description 文章管理实现类
 * @version 1.0
 * @date 2020/12/16 0016 11:02
 */
@Service
public class CmsArticleServiceImpl implements ICmsArticleService {

    @Resource
    private ArticleMapper articleMapper;

    @Override
    public List<Article> query(String title) {
        ArticleExample example = new ArticleExample();
        if(!StringUtils.isEmpty(title)){
            example.createCriteria().andTitleLike("%" + title + "%");
        }
        return articleMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Article article) {
        if(article.getId()==null){
            articleMapper.insert(article);
        }else {
            articleMapper.updateByPrimaryKey(article);
        }
    }

    @Override
    public void deleteById(long id) {
        articleMapper.deleteByPrimaryKey(id);
    }
}